/*******************************************************************************
Replication Materials for Blau, Kahn, Brummund, Cook, and Larson-Koester "Is 
There Still Son Preference in the United States?"

Table R17 - Table 5 on Extended Sample

See "CPS Read Me" for variable definitions

Date Modified: 10/23/2019

*******************************************************************************/

*Load data
use "$cps\regfile_March_ext", clear

*Keep only second generation immigrants that are the household head or spouse of household head
keep if secgen==1

*Drop observations with parents from countries without characteristics
drop if incountry == 0 

*Note additional restrictions made in regressions

/*******************************************************************************

I. Variable Cleaning and Generation

*******************************************************************************/

*Clean up some source country variables
	foreach mm in "m" "f" {
	
		*Log Transform GDP
		gen `mm'_ligdp00_07 = log(`mm'_igdp00_07)
		replace `mm'_igdp00_07 = `mm'_igdp00_07 / 10000 //scale by 10000

		*Censor Sex Ratio
		replace `mm'_isexratio00_07 =1.059   if `mm'_isexratio00_07  < 1.059
		ren	`mm'_isexratio00_07 `mm'_isr00_07

	}
	
*Define parent source country characteristics
	global varlist "lfp fert gdp sr score"

	foreach v of global varlist {
			cap drop igen`v'
			g igen`v' = m_i`v'00_07 if (own_imm_mom == 1) //use mother's country characteristics
			replace igen`v' = f_i`v'00_07 if (own_imm_mom == 0 & own_imm_dad == 1)  //use father's country characteristics if mother not an immigrant
			}

	cap drop ligengdp
	g ligengdp = m_ligdp00_07 if (own_imm_mom == 1)
	replace ligengdp = f_ligdp00_07 if (own_imm_mom == 0 & own_imm_dad == 1) //use father's country characteristics if mother not an immigrant
		
	cap drop ibpld
	g ibpld = m_bpld if (own_imm_mom == 1)
	replace ibpld = f_bpld if (own_imm_mom == 0 & own_imm_dad == 1)

*Spouse second generation indicator
	gen sp_secgen = 0
	replace sp_secgen = 1 if sp_imm_dad==1 | sp_imm_mom==1
	replace sp_secgen = 0 if sp_imm==1
	
*Generate Interactions
	gen girl_lfp = chld1*igenlfp
	gen girl_sr = chld1*igensr
	gen girl_ggi = chld1*igenscore

*Label Variables
	label var igenfert "Total Fertility"
	label var ligengdp "Log of GDP"
	label var igenscore "Equity Index"
	label var chld1 "First Child Girl"
	label var igenlfp "Labor Force Part."
	label var igensr "Sex Ratio at Birth"
	
	label var girl_lfp "Girl*Labor Force Part."
	label var girl_sr "Girl*Sex Ratio at Birth"
	label var girl_ggi "Girl*Equity Index"



/*******************************************************************************

II. Prob. Living without a Father Regressions

*******************************************************************************/

*Define Sample, Weights, and Controls
local sample "if (own_imm_mom == 1 | own_imm_dad== 1) & citizen!=1 & secgen==1 & gt0chld==1 & ext_samp==1"

local wgt "perwtnorm"

local controls "lths scol cold"
local controls "`controls' i.genrace i.region i.year age age2 age3"


*Column 1
local main "igenfert ligengdp igenscore chld1 girl_ggi"

reg femhdalt `main' `controls' `sample' [aw=`wgt'], cluster(ibpld)
qui sum femhdalt `sample'  [aw=`wgt']
local dep_mean : display %9.4f r(mean)
outreg2 using "$routput\Table_R17.xls", keep(`main') title("Table_R17: Effects of Source Country Characteristics on the Probability of Living Without a Father and Fertility, Second Generation Sample (At Least One Parent Foreign Born) [Table 5, Extended Sample]" ) ctitle(No Dad) addtext(Mean, `dep_mean') label dec(4) nocons nor2 replace

*Column 2
local main "igenfert ligengdp igenlfp chld1 girl_lfp"

reg femhdalt `main' `controls' `sample' [aw=`wgt'], cluster(ibpld)
qui sum femhdalt `sample'  [aw=`wgt']
local dep_mean : display %9.4f r(mean)
outreg2 using "$routput\Table_R17.xls", keep(`main') ctitle(No Dad) append addtext(Mean, `dep_mean') label dec(4) nocons nor2

*Column 3
local main "igenfert ligengdp igenlfp igensr chld1 girl_lfp girl_sr"

reg femhdalt `main' `controls' `sample' [aw=`wgt'], cluster(ibpld)
qui sum femhdalt `sample'  [aw=`wgt']
local dep_mean : display %9.4f r(mean)
outreg2 using "$routput\Table_R17.xls", keep(`main') ctitle(No Dad) append addtext(Mean, `dep_mean') label dec(4) nocons nor2

/*******************************************************************************

III. Fertility Regressions

*******************************************************************************/

*Define Sample, Weights, and Controls
local sample "if (own_imm_mom == 1 | own_imm_dad== 1) & citizen!=1 & secgen==1 & gt0chld==1 & ext_sampf==1"

local wgt "perwtnorm"

local controls "lths scol cold sp_lths sp_scol sp_cold" //leave out: hsdi
local controls "`controls' i.genrace i.sp_genrace i.region i.year age age2 age3" 
local controls "`controls' sp_age sp_age2 sp_age3 sp_imm sp_secgen"

*Column 1
local main "igenfert ligengdp igenscore chld1 girl_ggi"

reg nchild `main' `controls' `sample' [aw=`wgt'], cluster(ibpld)
qui sum nchild `sample'  [aw=`wgt']
local dep_mean : display %9.4f r(mean)
outreg2 using "$routput\Table_R17.xls", keep(`main') ctitle(Fertility) append addtext(Mean, `dep_mean') label dec(4) nocons nor2

*Column 2
local main "igenfert ligengdp igenlfp chld1 girl_lfp"

reg nchild `main' `controls' `sample' [aw=`wgt'], cluster(ibpld)
qui sum nchild `sample'  [aw=`wgt']
local dep_mean : display %9.4f r(mean)
outreg2 using "$routput\Table_R17.xls", keep(`main') ctitle(Fertility) append addtext(Mean, `dep_mean') label dec(4) nocons nor2

*Column 3
local main "igenfert ligengdp igenlfp igensr chld1 girl_lfp girl_sr"

reg nchild `main' `controls' `sample' [aw=`wgt'], cluster(ibpld)
qui sum nchild `sample'  [aw=`wgt']
local dep_mean : display %9.4f r(mean)
outreg2 using "$routput\Table_R17.xls", keep(`main') ctitle(Fertility) append addtext(Mean, `dep_mean') label dec(4) sortvar(igenfert ligengdp igenlfp igensr igenscore chld1 girl_lfp girl_sr girl_ggi) nocons nor2

